/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-05-09
 * Time: 16:43
 */
class Person {
    public String name;
    public String gender;
    public int age;

    Person(String name,String gender, int age) {
        this.name = name;
        this.gender = gender;
        this.age = age;
    }

    public String toString() {
        return "[" + this.name + ":" + this.gender + " "+ this.age + "]";
    }

    @Override
    public boolean equals(Object o) {
        //自己和自己比较
        if(this == o) {
            return true;
        }
        //o是null对象或者o不是Person的子类
        if(o == null || !(o instanceof Person)) {
            return false;
        }

        Person p = (Person)o;
        //基本数据类型如age为int类型可以直接用==比较
        //引用类型最好还是用equals比较
        return name.equals(p.name) && gender.equals(p.gender) && age == p.age;
    }
}


public class Test {
    public static void main(String[] args) {
        //比较引用数据类型
        Person[] person = new Person[] {
                new Person("泡泡","女",19),
                new Person("泡泡","女",19),
                new Person("柚柚","女",25),
                new Person("球球","男",25)
        };
        System.out.println(person[0] == person[1]);
        System.out.println(person[0].equals(person[1]));
    }

}



